package com.fractalwrench.harmonybootstrap.sample;

import static com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapBrand.DANGER;
import static com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapBrand.INFO;
import static com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapBrand.PRIMARY;
import static com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapBrand.REGULAR;
import static com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapBrand.SECONDARY;
import static com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapBrand.SUCCESS;
import static com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapBrand.WARNING;

import com.beardedhen.harmonybootstrap.BootstrapEditText;
import com.beardedhen.harmonybootstrap.utils.UiUtil;
import com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapBrand;
import com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapSize;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.element.ShapeElement;

public class BootstrapEditTextExample extends AbilitySlice  implements Component.ClickedListener {

    private BootstrapEditText changeRound, changeEnabled, changeTheme, changeSize;
    private Button changeEnabled_btn, changeTheme_btn, changeSize_btn, changeRound_btn;

    private DefaultBootstrapSize size = DefaultBootstrapSize.MD;
    private void setShapeElement(Button b) {
        b.setBackground(new UiUtil(getApplicationContext()).getShapeElement(ShapeElement.RECTANGLE, ResourceTable.Color_material_lighter_gray, 5.0f));
    }

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_example_bootstrap_edittext);

        ComponentContainer rootLayout = (ComponentContainer) LayoutScatter.getInstance(this)
                .parse(ResourceTable.Layout_example_bootstrap_edittext, null, false);


        changeRound = (BootstrapEditText) rootLayout.findComponentById(ResourceTable.Id_bedit_text_change_rounded);
        changeEnabled = (BootstrapEditText) rootLayout.findComponentById(ResourceTable.Id_bedit_text_change_enabled);
        changeTheme = (BootstrapEditText) rootLayout.findComponentById(ResourceTable.Id_bedit_text_change_theme);
        changeSize = (BootstrapEditText) rootLayout.findComponentById(ResourceTable.Id_bedit_text_change_size);

        changeRound_btn = (Button) rootLayout.findComponentById(ResourceTable.Id_bedit_text_change_rounded_btn);
        setShapeElement(changeRound_btn);
        changeEnabled_btn = (Button) rootLayout.findComponentById(ResourceTable.Id_bedit_text_change_enabled_btn);
        setShapeElement(changeEnabled_btn);
        changeTheme_btn = (Button) rootLayout.findComponentById(ResourceTable.Id_bedit_text_change_theme_btn);
        setShapeElement(changeTheme_btn);
        changeSize_btn = (Button) rootLayout.findComponentById(ResourceTable.Id_bedit_text_change_size_btn);
        setShapeElement(changeSize_btn);

        changeRound_btn.setClickedListener(this);
        changeEnabled_btn.setClickedListener(this);
        changeTheme_btn.setClickedListener(this);
        changeSize_btn.setClickedListener(this);

        super.setUIContent(rootLayout);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_bedit_text_change_theme_btn:
                onChangeThemeExampleClicked();
                break;
            case ResourceTable.Id_bedit_text_change_rounded_btn:
                changeRound.setRounded(!changeRound.isRounded());
                break;
            case ResourceTable.Id_bedit_text_change_enabled_btn:
                changeEnabled.setEnabled(!changeEnabled.isEnabled());
                break;
            case ResourceTable.Id_bedit_text_change_size_btn:
                onSizeExampleClicked();
                break;
            default:
                break;

        }
    }

    private void onChangeThemeExampleClicked() {
        switch ((DefaultBootstrapBrand) changeTheme.getBootstrapBrand()) {
            case PRIMARY:
                changeTheme.setBootstrapBrand(SUCCESS);
                break;
            case SUCCESS:
                changeTheme.setBootstrapBrand(INFO);
                break;
            case INFO:
                changeTheme.setBootstrapBrand(WARNING);
                break;
            case WARNING:
                changeTheme.setBootstrapBrand(DANGER);
                break;
            case DANGER:
                changeTheme.setBootstrapBrand(SECONDARY);
                break;
            case SECONDARY:
                changeTheme.setBootstrapBrand(REGULAR);
                break;
            case REGULAR:
                changeTheme.setBootstrapBrand(PRIMARY);
                break;
        }
    }

    private void onSizeExampleClicked() {
        switch (size) {
            case XS:
                size = DefaultBootstrapSize.SM;
                break;
            case SM:
                size = DefaultBootstrapSize.MD;
                break;
            case MD:
                size = DefaultBootstrapSize.LG;
                break;
            case LG:
                size = DefaultBootstrapSize.XL;
                break;
            case XL:
                size = DefaultBootstrapSize.XS;
                break;
        }
        changeSize.setBootstrapSize(size);
    }
}
